package 力扣日常刷题.木22一月.第18天0130;

/**
 * @author 帅小伙
 * @date 2022/1/30
 * @description 暴力
 * 计数排序
 * https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/submissions/
 */
public class Demo41数组简单有多少小于当前数字的数字 {

    public int[] smallerNumbersThanCurrent(int[] nums) {
        int[] cnt = new int[101];
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            cnt[nums[i]]++;
        }
        for (int i = 1; i <= 100 ; i++) {
            cnt[i] += cnt[i-1];
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            ans[i] = nums[i] == 0 ? 0 : cnt[nums[i] - 1];
        }
        return ans;
    }

}
